package game;

public abstract class AbstractRunnable
{
    public enum Status
    {
        RUNNING("RUNNING"), PAUSE("PAUSE"), RESET("RESET");
        private String status;
        
        private Status(String status)
        {
            this.status = status;
        }
        
        public String getStatus()
        {
            return status;
        }
    }
    
    private volatile String info   = "";
    private volatile Status status = Status.RESET;
    
    public synchronized void setInfo(String info)
    {
        this.info = info;
    }
    
    public synchronized String getInfo()
    {
        return info;
    }
    
    public boolean isRunning()
    {
        return status == Status.RUNNING;
    }
    
    public boolean isReset()
    {
        return status == Status.RESET;
    }
    
    public boolean isPaused()
    {
        return status == Status.PAUSE;
    }
    
    protected Status getStatus()
    {
        return status;
    }
    
    private void setStatus(Status status)
    {
        Logger.log("STATUS: " + status);
        this.status = status;
    }
    
    protected void start()
    {
        setStatus(Status.RUNNING);
    }
    
    protected void stop()
    {
        setStatus(Status.RESET);
    }
    
    public void pause()
    {
        setStatus(Status.PAUSE);
    }
    
    protected void resume()
    {
        setStatus(Status.RUNNING);
    }
    
    protected void reset()
    {
        setStatus(Status.RESET);
    }
    
    protected void restart()
    {
        stop();
        start();
    }
    
    protected abstract void doNext();
    
    public synchronized void update()
    {
        if (isRunning() && isPaused() == false)
        {
            doNext();
        }
    }
}
